class_name PlayerStateHurt
extends PlayerState

const DURATION_HURT := 1000
const HURT_HEIGHT_VELOCITY := 3.0
const BALL_TUMBLE_SPEED := 100
var time_start_hurt := 0

func _enter_tree() -> void:
	animation_player.play("hurt")
	time_start_hurt = Time.get_ticks_msec()
	player.height_velocity = HURT_HEIGHT_VELOCITY
	player.height = 0.1
	if ball.carried == player:
		ball.tumble(state_data.hurt_direction * BALL_TUMBLE_SPEED)
		SoundPlayer.play(SoundPlayer.Sound.HURT)
		GameEvent.impact_received(player.position)
	
func _process(_delta: float) -> void:
	if Time.get_ticks_msec() - time_start_hurt > DURATION_HURT:
		state_transition(Player.State.RECOVERING)
